set more off
import delimited "Data, February 2020.csv"
********************************************************************************

****
** Recode and create variables
****

* Attention checks
gen pass1 = 0
replace pass1 = 1 if q5 == 3

gen pass2 = 0
replace pass2 = 1 if q28 == 2

keep if pass1 == 1 & pass2 == 1


* Time spent completing survey
gen short = 0
replace short = 1 if durationinseconds < 420

drop if short == 1


* Egocentric victimhood
foreach v of var q2_1-q2_4{ 
	replace `v' = (`v' * -1) + 6
}

alpha q2_1-q2_4, gen(egocentric)

egen egocentric_sd = rowsd(q2_1-q2_4)


* Systemic victimhood
foreach v of var q3_1-q3_4{ 
	replace `v' = (`v' * -1) + 6
}

alpha q3_1-q3_4, gen(systemic)

egen systemic_sd = rowsd(q3_1-q3_4)

* Anxiety
alpha q6_1-q6_7, gen(anxiety)

egen anxiety_sd = rowsd(q6_1-q6_7)


* Powerlessness
foreach v of var q7_1-q7_2{ 
	replace `v' = (`v' * -1) + 6
}
alpha q7_1-q7_2, gen(powerless)

egen powerless_sd = rowsd(q7_1-q7_2)


* Conspiracy thinking
foreach v of var q9_1-q9_4{ 
	replace `v' = (`v' * -1) + 6
}

alpha q9_1-q9_4, gen(conthink)

egen conthink_sd = rowsd(q9_1-q9_4)


* How many in government are corrupt?
gen corrupt = (q10 * -1) + 6
replace corrupt = . if corrupt < 1


* Trust in government
gen trustgov = q11
replace trustgov = . if q11 > 5


* Racial resentment
foreach v of var q14_1 q14_4{ 
	replace `v' = (`v' * -1) + 6
}

alpha q14_1-q14_4, gen(raceresent)

egen raceresent_sd = rowsd(q14_1-q14_4)


* Populism
foreach v of var q15_1-q15_9{ 
	replace `v' = (`v' * -1) + 6
}

factor q15_1-q15_9, ipf
factor q15_1-q15_7 q15_9, ipf
alpha q15_1-q15_7 q15_9, gen(populism)

egen populism_sd = rowsd(q15_1-q15_7 q15_9)


* Authoritarianism
foreach v of var q16_1-q16_3{ 
	replace `v' = (`v' * -1) + 6
}

*gen authoritarian = q16_2
alpha q16_1-q16_3, gen(authoritarian)

egen authoritarian_sd = rowsd(q16_1-q16_3)


* Health insurance
gen insured = q17
recode insured (2=0)

gen employer = q18
recode employer (2=0)


* Vote choice
gen vote2020 = 0
replace vote2020 = 1 if q19 == 1

gen trumpvote = .
replace trumpvote = 1 if q20 == 1
replace trumpvote = 0 if q20 > 1 & q20 < .


* Partisanship
gen pid = .
replace pid = 1 if q23 == 1
replace pid = 2 if q23 == 2
replace pid = 3 if q24 == 2
replace pid = 4 if q24 == 3 | q24 == 4
replace pid = 5 if q24 == 1
replace pid = 6 if q22 == 2
replace pid = 7 if q22 == 1

gen pidstrength = abs(pid - 4) + 1

gen rep = .
replace rep = 1 if pid > 4 & pid < .
replace rep = 0 if pid < 4

gen pid3 = .
replace pid3 = 1 if pid < 4
replace pid3 = 2 if pid == 4
replace pid3 = 3 if pid > 4 & pid < .


* Ideology
gen ideo = q25
replace ideo = . if q25 > 7

gen ideostrength = abs(ideo - 4) + 1

gen conserv = .
replace conserv = 1 if ideo > 4 & ideo < .
replace conserv = 0 if ideo < 4

gen ideo3 = .
replace ideo3 = 1 if ideo < 4
replace ideo3 = 2 if ideo == 4
replace ideo3 = 3 if ideo > 4 & ideo < .


* Interest in politics
gen interest = (q26 * -1) + 5


* Trump thermometer
gen trumpft = q27_3




* Capitol riots and violence
gen justified = (q30_1 * -1) + 6

foreach v of var q30_2-q30_4{ 
	replace `v' = (`v' * -1) + 6
}

alpha q30_2-q30_4, gen(violence)

egen violence_sd = rowsd(q30_2-q30_4)


* Region
gen south = 0
replace south = 1 if q32 == 3


* Gender
gen female = 0
replace female = 1 if q33 == 2


* Latinx
gen latinx = 0
replace latinx = 1 if q34 == 1


* Race
gen race = .
replace race = 1 if q35_5 == 1
replace race = 2 if q35_3 == 1
replace race = 3 if q35_2 == 1
replace race = 4 if q35_1 == 1
replace race = 4 if q35_4 == 1

gen white = 0
replace white = 1 if q35_5 == 1

gen black = 0
replace black = 1 if q35_3 == 1


* Education
gen edu = q36

gen college = .
replace college = 0 if edu < 4
replace college = 1 if edu > 3 & edu < .


* Religious denomination
gen evangelical = 0
replace evangelical = 1 if q38 == 1


* Religiosity
gen attend = (q39 * -1) + 6


* Military service
gen military = 0
replace military = 1 if q40 < 3


* Income
gen income = q41
replace income = . if q41 == 6


* Age
gen agecat = .
replace agecat = 1 if age >= 18 & age < 25
replace agecat = 2 if age >= 25 & age < 45
replace agecat = 3 if age >= 45 & age < 65
replace agecat = 4 if age >= 65 & age < .



* White identity
foreach v of var q43-q46{ 
	replace `v' = (`v' * -1) + 6
}

alpha q43-q46, gen(whiteidentity)

egen whiteidentity_sd = rowsd(q43-q46)


* Rescale to range from 0 (min) to 1 (max)
foreach v of var whiteidentity income attend ///
	edu violence justified interest ideo pid ideostrength ///
	pidstrength egocentric systemic age trumpft{ 
	su `v', meanonly 
	gen `v'2 = (`v' - r(min))/(r(max) - r(min)) 
}

drop if violence == .

********************************************************************************

****
** Correlations
****

sem (<- violence systemic), standardize
sem (<- violence egocentric), standardize
sem (<- violence anxiety), standardize 
sem (<- violence powerless), standardize 
sem (<- violence populism), standardize
sem (<- violence authoritarian), standardize
sem (<- violence conthink), standardize 
sem (<- violence corrupt), standardize 
sem (<- violence trust), standardize 
sem (<- violence interest), standardize 
sem (<- violence whiteidentity), standardize 
sem (<- violence raceresent), standardize 
sem (<- violence ideostrength), standardize
sem (<- violence pidstrength), standardize 
sem (<- violence rep), standardize 
sem (<- violence conserv), standardize 
sem (<- violence attend), standardize 
sem (<- violence evangelical), standardize 
sem (<- violence military), standardize 
sem (<- violence income), standardize 
sem (<- violence insured), standardize
sem (<- violence edu), standardize 
sem (<- violence female), standardize 
sem (<- violence south), standardize

********************************************************************************

****
** Generate profile and then
** model attitudes about riot
****

gen profile = .
replace profile = 1 if systemic <= 3.5 & populism <= 2.625 & raceresent <= 2	
replace profile = 2 if systemic <= 3.5 & populism <= 2.625 & raceresent > 2
replace profile = 3 if systemic <= 3.5 & populism > 2.625 & authoritarian <= 4 & systemic <= 2.75
replace profile = 4 if systemic <= 3.5 & populism > 2.625 & authoritarian <= 4 & systemic > 2.75
replace profile = 5 if systemic <= 3.5 & populism > 2.625 & authoritarian > 4
replace profile = 6 if military == 0 & systemic > 3.5 & whiteidentity <= 4.25
replace profile = 7 if authoritarian <= 3 & military > 0 & systemic > 3.5
replace profile = 8 if military == 0 & systemic > 3.5 & whiteidentity > 4.25
replace profile = 9 if authoritarian > 3 & military > 0 & systemic > 3.5

su profile, meanonly 
gen profile2 = (profile - r(min))/(r(max) - r(min)) 

hist profile
corr profile justified violence

* Naive model
reg justified i.pid3 i.ideo3 pidstrength2 ideostrength2 interest2 edu2 ///
	age2 income2 female white south
est store mod1

* With Trump thermometer
reg justified i.pid3 i.ideo3 pidstrength2 ideostrength2 interest2 edu2 ///
	age2 income2 female white south trumpft2
est store mod2	

* With Trump thermometer + violence profile
reg justified i.pid3 i.ideo3 pidstrength2 ideostrength2 interest2 edu2 ///
	age2 income2 female white south trumpft2 profile2
est store mod3	

margins, at(trumpft2=(0(0.1)1))	
matrix list r(table)
matrix m0 = r(at)
matrix  m11 = m0[1..., "trumpft2"]
matrix m1 = r(table)
matrix  m12 = m1["b", 1...]'
matrix m13 = m1["ll".."ul",1...]'
matrix first = m11,m12,m13

margins, at(profile2=(0(0.1)1))	
matrix m2 = r(at)
matrix  m21 = m2[1..., "profile2"]
matrix m3 = r(table)
matrix m31 = m3["b", 1...]'
matrix m32 = m3["ll".."ul",1...]'
matrix second = m21,m31,m32

matrix rownames first = 1
matrix rownames second = 2
matrix colnames first = scale estimate lower upper

matrix RESULTS = first \ second

* Save predictions
preserve
matsave RESULTS, dropall
rename _rowname order
saveold "Justified Predictions.dta", version(12) replace
erase RESULTS.dta
clear
restore	

* With interaction between Trump thermometer and violence profile
reg justified i.pid3 i.ideo3 pidstrength2 ideostrength2 interest2 edu2 ///
	age2 income2 female white south c.trumpft2##c.profile2
est store mod4	
margins, dydx(profile2) at(trumpft2=(0(0.1)1))	
matrix list r(table)
matrix m0 = r(at)
matrix  m11 = m0[1..., "trumpft2"]
matrix m1 = r(table)
matrix  m12 = m1["b", 1...]'
matrix m13 = m1["ll".."ul",1...]'
matrix first = m11,m12,m13

matrix rownames first = 1
matrix colnames first = scale estimate lower upper

matrix RESULTS = first

* Save predictions
preserve
matsave RESULTS, dropall
rename _rowname order
saveold "Justified Marginal Effects.dta", version(12) replace
erase RESULTS.dta
clear
restore	

* Save model estimates
esttab mod1 mod2 mod3 mod4 using "Justified Estimates.tex", ///
	cells(b(star fmt(3)) se(par fmt(3))) legend label ///
	varlabels(_cons Constant) stats(r2 N, fmt(3 0 1)) ///
	addnotes(Note: OLS coefficients with standard errors in parentheses)	

********************************************************************************

****
** Controlling for everything 
** separately
****

* Sans profile
reg justified pid2 ideo2 interest2 college age2 income2 female white south ///
	egocentric systemic anxiety powerless conthink whiteidentity ///
	corrupt trustgov raceresent populism authoritarian insured military
est store mod5	
	
* With Trump support	
reg justified pid2 ideo2 interest2 college age2 income2 female white south ///
	trumpft2 egocentric systemic anxiety powerless conthink whiteidentity ///
	corrupt trustgov raceresent populism authoritarian insured military
est store mod6	

* With profile	
reg justified pid2 ideo2 interest2 college age2 income2 female white south ///
	trumpft2 egocentric systemic anxiety powerless conthink whiteidentity ///
	corrupt trustgov raceresent populism authoritarian insured military ///
	profile2 
est store mod7	

margins, at(trumpft2=(0(0.1)1))	
matrix list r(table)
matrix m0 = r(at)
matrix  m11 = m0[1..., "trumpft2"]
matrix m1 = r(table)
matrix  m12 = m1["b", 1...]'
matrix m13 = m1["ll".."ul",1...]'
matrix first = m11,m12,m13

margins, at(profile2=(0(0.1)1))	
matrix m2 = r(at)
matrix  m21 = m2[1..., "profile2"]
matrix m3 = r(table)
matrix m31 = m3["b", 1...]'
matrix m32 = m3["ll".."ul",1...]'
matrix second = m21,m31,m32

matrix rownames first = 1
matrix rownames second = 2
matrix colnames first = scale estimate lower upper

matrix RESULTS = first \ second

* Save predictions
preserve
matsave RESULTS, dropall
rename _rowname order
saveold "Justified Predictions, NBREG.dta", version(12) replace
erase RESULTS.dta
clear
restore	
		
* With profile and Trump thermometer interactions		
reg justified pid2 ideo2 interest2 college age2 income2 female white south ///
	egocentric systemic anxiety powerless conthink whiteidentity ///
	corrupt trustgov raceresent populism authoritarian insured military ///
	c.trumpft2##c.profile2		
est store mod8
margins, dydx(profile2) at(trumpft2=(0(0.1)1))	
matrix list r(table)
matrix m0 = r(at)
matrix  m11 = m0[1..., "trumpft2"]
matrix m1 = r(table)
matrix  m12 = m1["b", 1...]'
matrix m13 = m1["ll".."ul",1...]'
matrix first = m11,m12,m13

matrix rownames first = 1
matrix colnames first = scale estimate lower upper

matrix RESULTS = first

* Save predictions
preserve
matsave RESULTS, dropall
rename _rowname order
saveold "Justified Marginal Effects, NBREG.dta", version(12) replace
erase RESULTS.dta
clear
restore	

* Save model estimates
esttab mod5 mod6 mod7 mod8 using "Garbage Can Estimates.tex", ///
	cells(b(star fmt(3)) se(par fmt(3))) legend label ///
	varlabels(_cons Constant) stats(r2 N, fmt(3 0 1)) ///
	addnotes(Note: OLS coefficients with standard errors in parentheses.)	
	
********************************************************************************

****
** Using negative binomial
****

* Naive model
nbreg justified i.pid3 i.ideo3 pidstrength2 ideostrength2 interest2 edu2 ///
	age2 income2 female white south
est store mod9

* With Trump thermometer
nbreg justified i.pid3 i.ideo3 pidstrength2 ideostrength2 interest2 edu2 ///
	age2 income2 female white south trumpft2
est store mod10	

* With Trump thermometer + violence profile
nbreg justified i.pid3 i.ideo3 pidstrength2 ideostrength2 interest2 edu2 ///
	age2 income2 female white south trumpft2 profile2
est store mod11	

* With interaction between Trump thermometer and violence profile
nbreg justified i.pid3 i.ideo3 pidstrength2 ideostrength2 interest2 edu2 ///
	age2 income2 female white south c.trumpft2##c.profile2
est store mod12	

* Save model estimates
esttab mod9 mod10 mod11 mod12 using "NBREG Estimates.tex", ///
	cells(b(star fmt(3)) se(par fmt(3))) legend label ///
	varlabels(_cons Constant) stats(r2 N, fmt(3 0 1)) ///
	addnotes(Note: MLE coefficients with standard errors in parentheses.)	


********************************************************************************
	
**** 
** Appendix analyses
****

**** 
** Satisficing?
****

* Lower for "satisficers"	
gen violence_sat = .
replace violence_sat = 0 if violence_sd == 0
replace violence_sat = 1 if violence_sd > 0
ttest violence, by(violence_sat)

* No difference
gen populism_sat = .
replace populism_sat = 0 if populism_sd == 0
replace populism_sat = 1 if populism_sd > 0
ttest populism, by(populism_sat)

* No difference
gen authoritarian_sat = .
replace authoritarian_sat = 0 if authoritarian_sd == 0
replace authoritarian_sat = 1 if authoritarian_sd > 0
ttest authoritarian, by(authoritarian_sat)
	
* Higher for "satisficers"		
gen whiteidentity_sat = .
replace whiteidentity_sat = 0 if whiteidentity_sd == 0
replace whiteidentity_sat = 1 if whiteidentity_sd > 0
ttest whiteidentity, by(whiteidentity_sat)

* No difference
gen raceresent_sat = .
replace raceresent_sat = 0 if raceresent_sd == 0
replace raceresent_sat = 1 if raceresent_sd > 0
ttest raceresent, by(raceresent_sat)
	
* Lower for "satisficers"		
gen systemic_sat = .
replace systemic_sat = 0 if systemic_sd == 0
replace systemic_sat = 1 if systemic_sd > 0
ttest systemic, by(systemic_sat)

* Lower for "satisficers"		
gen egocentric_sat = .
replace egocentric_sat = 0 if egocentric_sd == 0
replace egocentric_sat = 1 if egocentric_sd > 0
ttest egocentric, by(egocentric_sat)

* Lower for "satisficers"		
gen anxiety_sat = .
replace anxiety_sat = 0 if anxiety_sd == 0
replace anxiety_sat = 1 if anxiety_sd > 0
ttest anxiety, by(anxiety_sat)

* Lower for "satisficers" 
gen powerless_sat = .
replace powerless_sat = 0 if powerless_sd == 0
replace powerless_sat = 1 if powerless_sd > 0
ttest powerless, by(powerless_sat)

* Higher for "satisficers" 
gen conthink_sat = .
replace conthink_sat = 0 if conthink_sd == 0
replace conthink_sat = 1 if conthink_sd > 0
ttest conthink, by(conthink_sat)

* Overall satisficing measure
egen satisfice = rowtotal(conthink_sat powerless_sat anxiety_sat ///
	egocentric_sat systemic_sat raceresent_sat whiteidentity_sat ///
	populism_sat authoritarian_sat)
replace satisfice = 9 - satisfice 	

pwcorr violence satisfice, sig		
pwcorr justified satisfice, sig			
	
